package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.annotation.Log;
import com.qf.entity.ProductSku;
import com.qf.service.ProductSkuService;
import com.qf.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 */
@RestController
@RequestMapping("/sku")
public class ProductSkuController {

    @Autowired
    private ProductSkuService productSkuService;

    @GetMapping("/findAlll")
    @Log(value = "库存查询全部", type = "查询")
    public R skufindAll (ProductSku productSku) {
        /*
        分页查询全部
         */
        PageHelper.startPage(productSku.getPageNum(), productSku.getPageSize());
        List<ProductSku> sku = productSkuService.skufindAll(productSku);
        PageInfo<ProductSku> pageInfo = new PageInfo<>(sku);

        return R.ok(pageInfo);
    }

    /*
    条件模糊查询
     */
    @GetMapping("/fuzzy")
    @Log(value = "库存模糊查询", type = "查询")

    public R skuFuzzy (ProductSku productSku) {

        PageHelper.startPage(productSku.getPageNum(), productSku.getPageSize());
        List<ProductSku> sku = productSkuService.skuFuzzy(productSku);
        PageInfo<ProductSku> pageInfo = new PageInfo<>(sku);
        long id = 0;
        if (id != 0) {

            return R.ok(pageInfo);
        }
        return R.fail();
    }

    @PostMapping("/skugoods")
    @Log(value = "修改库存信息", type = "修改")

    public R modifyGoodsSku (@RequestBody ProductSku submitData) {
        boolean ok = productSkuService.GoodsSku(submitData);
        if (ok){


        return R.ok();
        }
        return R.fail();
    }

    /*
    添加库存
     */
    @PostMapping("/goods")
    @Log(value = "添加库存商品", type = "添加")

    public R GoodsSku (@RequestBody ProductSku formData) {
        boolean ok = productSkuService.ProductGoodsSku(formData);
        return R.ok();
    }

    /*
    根据id删除
     */
    @DeleteMapping("/delete/{id}")
    @Log(value = "删除库存商品", type = "删除")

    public R handleDelete (@PathVariable Integer id) {
        boolean ok = productSkuService.handleDelete(id);
        if (ok) {
            return R.ok();
        }
        return R.fail();
    }
}
